package com.gonsin.gview.model.dynamic.form;

import com.gonsin.gview.model.GFormItemModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@ApiModel("文本输入框的描述")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DynamicFile extends DynamicFormItem {

    @ApiModelProperty("file表示文件上传框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private final String itemType = "file";

    @ApiModelProperty("是否必选")
    private boolean required = true;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("查询或者提交表单时，表示  文件的文件名")
    private String filenameKeyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("提示的文本")
    private String placeholder;

    @ApiModelProperty("文件大小限制，单位B")
    private long maxSize;

    @ApiModelProperty("支持文件格式")
    private String accept;

    @ApiModelProperty("支持上传多少个文件，如果多个文件，则组成字符串  /files/xxx.xx,/files/xxx.yy")
    private int limit;

    @ApiModelProperty("动态显示的js脚本，用于控制特定情况下该输入框的隐藏和显示")
    private String showIf = "1";

    @ApiModelProperty("根据情况禁用")
    private String disableIf = "0";

    @ApiModelProperty("可支持的文件上传类型，如果是file，表示只支持文件，" +
            "如果是path，表示支持文件和文件夹")
    private String fileUploadType;


    public static DynamicFileBuilder builder() {
        return new DynamicFileBuilder();
    }

    public static final class DynamicFileBuilder {
        @ApiModelProperty("file表示文件上传框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
        private final String itemType = "file";

        @ApiModelProperty("是否必选")
        private boolean required = true;

        @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
        private String keyName;

        @ApiModelProperty("查询或者提交表单时，表示  文件的文件名")
        private String filenameKeyName;

        @ApiModelProperty("显示的名字")
        private String name;

        @ApiModelProperty("提示的文本")
        private String placeholder;

        @ApiModelProperty("文件大小限制，单位B")
        private long maxSize;

        @ApiModelProperty("支持文件格式")
        private String accept;

        @ApiModelProperty("支持上传多少个文件，如果多个文件，则组成字符串  /files/xxx.xx,/files/xxx.yy")
        private int limit;

        @ApiModelProperty("动态显示的js脚本，用于控制特定情况下该输入框的隐藏和显示")
        private String showIf = "1";

        @ApiModelProperty("根据情况禁用")
        private String disableIf = "0";

        @ApiModelProperty("可支持的文件上传类型，如果是file，表示只支持文件，" +
                "如果是path，表示支持文件和文件夹")
        private String fileUploadType;

        private DynamicFileBuilder() {
        }

        public DynamicFileBuilder required(boolean required) {
            this.required = required;
            return this;
        }

        public DynamicFileBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicFileBuilder filenameKeyName(String filenameKeyName) {
            this.filenameKeyName = filenameKeyName;
            return this;
        }

        public DynamicFileBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicFileBuilder placeholder(String placeholder) {
            this.placeholder = placeholder;
            return this;
        }

        public DynamicFileBuilder maxSize(long maxSize) {
            this.maxSize = maxSize;
            return this;
        }

        public DynamicFileBuilder accept(String accept) {
            this.accept = accept;
            return this;
        }

        public DynamicFileBuilder limit(int limit) {
            this.limit = limit;
            return this;
        }

        public DynamicFileBuilder showIf(String showIf) {
            this.showIf = showIf;
            return this;
        }

        public DynamicFileBuilder disableIf(String disableIf) {
            this.disableIf = disableIf;
            return this;
        }

        public DynamicFileBuilder fileUploadType(String fileUploadType) {
            this.fileUploadType = fileUploadType;
            return this;
        }

        public DynamicFile build() {
            DynamicFile dynamicFile = new DynamicFile();
            dynamicFile.setRequired(required);
            dynamicFile.setKeyName(keyName);
            dynamicFile.setFilenameKeyName(filenameKeyName);
            dynamicFile.setName(name);
            dynamicFile.setPlaceholder(placeholder);
            dynamicFile.setMaxSize(maxSize);
            dynamicFile.setAccept(accept);
            dynamicFile.setLimit(limit);
            dynamicFile.setShowIf(showIf);
            dynamicFile.setDisableIf(disableIf);
            dynamicFile.setFileUploadType(fileUploadType);
            return dynamicFile;
        }
    }
}
